package com.neu.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.neu.R;
import com.neu.bean.ServiceList;
import com.neu.util.VolleyUtil;
import com.neu.view.App;

import java.util.List;

public class RecServiceAdapter extends RecyclerView.Adapter<RecServiceAdapter.ViewHolder> {

    private List<ServiceList.RowsBean> list;

    public RecServiceAdapter(List<ServiceList.RowsBean> list){
        this.list=list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(App.context).inflate(R.layout.home_service_adaper_layout,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ServiceList.RowsBean rs=list.get(position);
        holder.txtServiceName.setText(rs.getServiceName());
        String url=rs.getImgUrl();
        Glide.with(App.context).load(VolleyUtil.BASE_URL+url).into(holder.imgService);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        //定义视图中的组件
        private ImageView imgService;
        private TextView txtServiceName;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            //获得视图组件的实例
            imgService=itemView.findViewById(R.id.imgService);
            txtServiceName=itemView.findViewById(R.id.txtServiceName);
        }
    }
}
